import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { RecordService } from './record.service';
import { CreateRecordDto } from './dto/create-record.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { UpdateRecordDto } from './dto/update-record.dto';
import { Record } from './entities/record.entity';
import { ReqUser } from '../../../common/decorator/user.decorator';

@Controller()
export class RecordController {
  constructor(private readonly recordService: RecordService) {}

  @Post()
  create(@Body() createRecordDto: CreateRecordDto) {
    return this.recordService.create(createRecordDto);
  }

  @Post('list')
  findAll(@Body() pageQuery: PageQuery<Record>, @ReqUser('id') userId: number) {
    return this.recordService.findAll(pageQuery, userId);
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.recordService.findOne(id);
  }

  @Patch(':id')
  update(@Param('id') id: number, @Body() updateRecordDto: UpdateRecordDto) {
    return this.recordService.update(id, updateRecordDto);
  }

  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.recordService.remove(id);
  }
}
